#include "structure/Water.h"
#include "Constants.h"
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform2.hpp>
#include <glm/gtx/projection.hpp>
#include <GL/glut.h>

Water::Water(GLuint programHandler, GLShaderConfig shaderConfig, float widthX, float widthY) :
	GLStructure(programHandler, shaderConfig),
	widthX(widthX),
	widthY(widthY),
	offset(0) {
	water = new Surface(programHandler, shaderConfig, widthX, widthY);
	water->setColor(0.2, 0.2, 0.8);
}

Water::~Water() {
	delete water;
}

void Water::updateComponents() {
//	glm::mat4 transformation = glm::translate(transformationMatrix, glm::vec3(0, 0, -height / 2));
//	transformation = glm::scale(transformation, glm::vec3(widthX, widthY, height));
	water->transform(transformationMatrix);

	float offset1 = glutGet(GLUT_ELAPSED_TIME) / 1000.0 * 2*3.14159 * .75;
	int offset1Location = glGetUniformLocation(this->programHandler, "Offset1");
	if( offset1Location >= 0 )
	{
		glUniform1f(offset1Location, offset1);
	}

	float offset2 = glutGet(GLUT_ELAPSED_TIME) / 1000.0 * 2*3.14159 * .50;
	int offset2Location = glGetUniformLocation(this->programHandler, "Offset2");
	if( offset2Location >= 0 )
	{
		glUniform1f(offset2Location, offset2);
	}
}

void Water::update (glm::mat4 viewMatrix, glm::mat4 modelMatrix) {
	updateComponents();
	water->update(viewMatrix, modelMatrix);
}
